<%= turbo_frame_tag :dialog do %>
  <div data-controller="search-picker">
    <%= dialog_header(Spree.t(:add_variant)) %>
    <div class="dialog-body">
      <%= form_with url: spree.admin_variants_search_path, method: :post, data: { controller: 'auto-submit', turbo_frame: '_top' } do |form| %>
        <%= form.hidden_field :omit_ids, value: @order.variant_ids.join(',') %>
        <%= form.hidden_field :param_name, value: 'line_item' %>
        <%= form.search_field :q, value: params[:q], class: 'form-control', data: { search_picker_target: :search, action: 'auto-submit#submit' }, autofocus: true %>
        <%= form.hidden_field :currency, value: @order.currency %>
      <% end %>
    </div>
    <%= form_with model: @line_item, url: spree.admin_order_line_items_path(@order), data: {turbo_frame: '_top'} do |form| %>
      <div class="dialog-body">
        <div id="variants_search_results" class="search-results">
          <p class="text-muted text-center py-5">
            <%= Spree.t(:start_typing_to_search_for_variants) %>
          </p>
        </div>
      </div>
      <div class="dialog-footer">
        <div class="d-flex gap-2 m-0 align-items-center mr-auto">
          <%= form.label :quantity, Spree.t(:quantity), class: "mb-0" %>
          <%= form.number_field :quantity, class: "form-control", min: 1 %>
        </div>
        <%= turbo_save_button_tag Spree.t(:add_selected_variant), disabled: true, data: { search_picker_target: :submit } %>
      </div>
    <% end %>
  </div>
<% end %>
